<?php
include_once("../../../../config.php");


$act   =  $_REQUEST['act'] ?  :'';

if($act == 'add'){

    $prom["upfile"] = $_FILES["file"];
    $prom["path"] = '../../../../uploadfiles/event/';
    $prom["allowExt"] = array('jpeg','jpg','png','gif','bmp');
    $img_url = upload_file($prom);

     $imageList = array();
     $imageList['ai_obj_nid'] = $_REQUEST['nid'];
     $imageList['ai_type'] = 'event';
     $imageList['ai_url'] = domain_img().$img_url['name'];
     $imageList['ai_add_time'] = date("Y-m-d H:i:s");
     $imageList['ai_name'] = substr($img_url['name'],strripos($img_url['name'],"/")+1);
     $image_sql   =insert_date("athlon_files",$imageList);
     $query = do_query($image_sql) or die (mysqli_error().$image_sql);


    if($query){
        $arr['status'] = 200;
        $arr['info'] = '上传成功';
        $arr['url'] = domain_img().$img_url['name'];
        $arr['url'] = domain_img().$img_url['name'];
        die(json_encode($arr)) ;
    }
    else{
        $arr['status'] = 501;
        $arr['info'] = '上传失败';
        $arr['url'] = '';
        die(json_encode($arr)) ;
    }


}else if($act == 'delete'){

    //删除记录
    $detail = select_one_line_all_items($table_Prefix."files", " type = 'event' AND nid= '".$_REQUEST['nid']."'");
    if($detail){
        $deleteSql = "DELETE FROM athlon_files  WHERE type = 'event' AND nid = ".$detail['nid'];
        $query = do_query($deleteSql) or die (mysqli_error().$deleteSql);
    }

    //删除文件
    $file_name = '../../uploadfiles/event/'.$detail['name'];
    if (is_file($file_name)) {
        //删除图片
        unlink($file_name);
    }

    $arr['status'] = 200;
    $arr['info'] = '删除成功';
    $arr['data'] = true;
    die(json_encode($arr)) ;
}

